package com.example.aicloud.controller;

import com.example.aicloud.entity.Comment;
import com.example.aicloud.service.ICommentService;
import com.example.aicloud.util.ResponseEntity;
import com.example.aicloud.util.SecurityUtil;
import com.example.aicloud.util.idempotent.Idempotent;
import jakarta.annotation.Resource;
import org.simpleframework.xml.core.Validate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/comment")
public class CommentController {
    /**
     * 添加评论
     */
    @Resource
    private ICommentService commentService;
    @PostMapping("/add")
    @Idempotent
    public ResponseEntity add(@Validate Comment comment){
        comment.setUid(SecurityUtil.getCurrentUser().getUid());
        boolean result = commentService.save(comment);
        if (result){
            return ResponseEntity.success("添加成功");
        }else {
            return ResponseEntity.fail("添加失败,请重试！");
        }
    }
}
